package com.huajin.iot.common.controller;

import com.huajin.iot.common.domain.LogDO;
import com.huajin.iot.common.domain.PageDO;
import com.huajin.iot.common.service.LogService;
import com.huajin.iot.common.utils.Query;
import com.huajin.iot.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = {"日志接口"})
@RequestMapping("/common/log")
@RestController
public class LogController {
    @Autowired
    LogService logService;
    String prefix = "common/log";


    @ApiOperation("日志列表")
    @ResponseBody
    @PostMapping("/list")
    R list(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        PageDO<LogDO> page = logService.queryList(query);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("list", page);
        return R.ok(resultMap);
    }

    @ApiOperation("删除一条日志")
    @ResponseBody
    @PostMapping("/remove")
    R remove(Long id) {
        if (logService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation("批量删除日志")
    @ResponseBody
    @PostMapping("/batchRemove")
    R batchRemove(@RequestParam("ids[]") Long[] ids) {
        int r = logService.batchRemove(ids);
        if (r == ids.length) {
            return R.ok();
        }
        return R.error();
    }
}
